const initState = {
  todos: []
}

export default (state=initState, action) => {
  if (action.type === 'ADD_TODO') {
    return {
      ...state,
      todos: [...state.todos, action.data]
    }
  }

  if (action.type === 'DEL_TODO') {
    let newTodos = [...state.todos]
    newTodos.splice(action.index, 1)
    return {
      ...state,
      todos: newTodos
    }
  }

  if (action.type === 'INIT_TODO') {
    return {
      ...state,
      todos: action.data
    }
  }
  return state
}